<?php
$MSG_ERR = 0;
if($GetMethodParams[1]['METRIC']=='FIXEDSIZE' && strlen($data[0]) != $GetMethodParams[1]['LENGTH']){
	echo $Msg_ERROR = 'Dados Inválidos: Comprimento de linha';
} elseif($GetMethodParams[1]['METRIC']=='VARSIZE' && count($data) != $GetMethodParams[1]['LENGTH']){
	echo $Msg_ERROR = 'Dados Inválidos: N campos invalido';
} else {
	$row++;
	$fdata[0] = substr($data[0],0,1);
	if($fdata[0] === 'N') {																																												#METHOD CODE	R	1	Char
		$ftdata .= '(&#TransactOrder#&,\''.$sysTime.'\',';
		$ftdata_extend .= '(&#ExtendedID'.$row.'#&,';
		$ftdata_income .= '(&#ExtendedID'.$row.'#&,';
		$ftdata_income .=  	$CorrProperties[1]['CorrNumero'].',&#TransactOrder#&,&#TransactTrans#&,';
		$fdata[1] = substr($data[0],1,8);	if(!frm_fldcheck($fdata[1],'INT',8,1)){$MSG_ERR = 1;} 	$fdata[1]=isocode_replace($__sysDomains,'p'.$fdata[1],0);	$ftdata .=		$fdata[1].',';											#AGENT	R	8	Integer
		$fdata[2] = substr($data[0],9,8);	if(!frm_fldcheck($fdata[2],'DAT',8,1)){$MSG_ERR = 2;} 																$ftdata_income .=	'"'.$fdata[2].'",';											#DATE	R	8	YYYYMMDD
		$fdata[3] = substr($data[0],17,10);	if(!frm_fldcheck($fdata[3],'INT',10,1)){$MSG_ERR = 3;}																$ftdata_income .=		$fdata[3].',';									#CORRESPONDENT REFERENCE	R	10	Integer
		#$fdata[4] = substr($data[0],27,8);	if(!frm_fldcheck($fdata[4],'INT',8,1)){$MSG_ERR = 4;} 																$ftdata .=		'null,';												#AGENT REFERENCE	R	8	Integer
		$fdata[5] = substr($data[0],35,8);	if(!frm_fldcheck($fdata[5],'DEC',8,1)){$MSG_ERR = 5;}																$ftdata .=		substr($fdata[5],0,6).'.'.substr($fdata[5],6,2).',';	#SENT	R	8	Decimal (8.2)
		$fdata[6] = substr($data[0],43,8);	if(!frm_fldcheck($fdata[6],'DEC',8,1)){$MSG_ERR = 6;} 																$ftdata .=		substr($fdata[6],0,6).'.'.substr($fdata[6],6,2).',';	#FX	R	8	Decimal (8.4)
		$fdata[7] = substr($data[0],51,6);	if(!frm_fldcheck($fdata[7],'DEC',6,1)){$MSG_ERR = 7;} 																$ftdata_income .=	substr($fdata[7],0,4).'.'.substr($fdata[7],4,2).',';#COMMISION	R	6	Decimal (6.2)
		$fdata[8] = substr($data[0],57,10);	if(!frm_fldcheck($fdata[8],'DEC',10,1)){$MSG_ERR = 8;} 																$ftdata .=		substr($fdata[8],0,8).'.'.substr($fdata[8],8,2).',';	#AMOUNT TO BE PAID	R	10	Decimal (10.2)
		$fdata[9] = substr($data[0],67,3);	if(!frm_fldcheck($fdata[9],'ALP',3,1)){$MSG_ERR = 9;} 	$fdata[9]=isocode_replace($__sysCurrency,'p'.$fdata[9],0);	$ftdata .=	$fdata[9].',';												#PAYMENT CURRENCY	R	3	Alphanumeric
		$fdata[10] = substr($data[0],70,100);	if(!frm_fldcheck($fdata[10],'ALP',100,1)){$MSG_ERR = 10;} 															$ftdata .=	'"'.trim($fdata[10]).'",';									#MESSAGE TO RECIPIENT		100	Alphanumeric
		$fdata[11] = substr($data[0],170,20);	if(!frm_fldcheck($fdata[11],'ALP',20,1)){$MSG_ERR = 11;} 															$ftdata_extend .=	'"'.trim($fdata[11]).' ';							#SENDER FIRST NAME	R	20	Alphanumeric
		$fdata[12] = substr($data[0],190,20);	if(!frm_fldcheck($fdata[12],'ALP',20,1)){$MSG_ERR = 12;} 															$ftdata_extend .=		trim($fdata[12]).'",';							#SENDER LAST NAME	R	20	Alphanumeric
		$fdata[13] = substr($data[0],210,20);	if(!frm_fldcheck($fdata[13],'ALP',20,1)){$MSG_ERR = 13;} 															$ftdata_extend .=	'"'.trim($fdata[13]).'",';							#SENDER ID DOC NUMBER		20	Alphanumeric
		$fdata[14] = substr($data[0],230,20);	if(!frm_fldcheck($fdata[14],'ALP',20,1)){$MSG_ERR = 14;} 															$ftdata_extend .=	'"'.trim($fdata[14]).' ';							#RECIPIENT 1st  FIRSTNAME	R	20	Alphanumeric
		$fdata[15] = substr($data[0],250,20);	if(!frm_fldcheck($fdata[15],'ALP',20,1)){$MSG_ERR = 15;} 															$ftdata_extend .=		trim($fdata[15]).' ';							#RECIPIENT 2nd FIRSTNAME		20	Alphanumeric
		$fdata[16] = substr($data[0],270,20);	if(!frm_fldcheck($fdata[16],'ALP',20,1)){$MSG_ERR = 16;} 															$ftdata_extend .=		trim($fdata[16]).' ';							#RECIPIENT 1st  LASTNAME	R	20	Alphanumeric
		$fdata[17] = substr($data[0],290,20);	if(!frm_fldcheck($fdata[17],'ALP',20,1)){$MSG_ERR = 17;} 															$ftdata_extend .=		trim($fdata[17]).'",';							#RECIPIENT 2nd LASTNAME		20	Alphanumeric
		$fdata[18] = substr($data[0],310,16);	if(!frm_fldcheck($fdata[18],'ALP',50,1)){$MSG_ERR = 18;} 															$ftdata_extend .=	'"'.trim($fdata[18]).'",';							#RECIPIENT DOCUMENT		16	Alphanumeric
		$fdata[19] = substr($data[0],326,50);	if(!frm_fldcheck($fdata[19],'ALP',50,1)){$MSG_ERR = 19;} 															$ftdata_extend .=	'"'.trim($fdata[19]).'",';							#RECIPIENT ADDRESS		50	Alphanumeric
		$fdata[20] = substr($data[0],376,50);	if(!frm_fldcheck($fdata[20],'ALP',50,1)){$MSG_ERR = 20;} 															$ftdata_extend .=	'"'.trim($fdata[20]).'",';							#RECIPIENT NEIGHBORHOOD		50	Alphanumeric
		$fdata[21] = substr($data[0],426,20);	if(!frm_fldcheck($fdata[21],'ALP',20,1)){$MSG_ERR = 21;} $fdata[21]=isocode_replace($__sysCities,'p'.$fdata[21],1);	$ftdata_extend .=	trim($fdata[21]).',';								#RECIPIENT CITY	R	20	Alphanumeric
		#	$fdata[22] = substr($data[0],446,20);	if(!frm_fldcheck($fdata[22],'ALP',20,1)){$MSG_ERR = 22;}														 	$ftdata_extend .=	'"'.trim($fdata[22]).'",';							#RECIPIENT PROVINCE 	R	20	Alphanumeric
		$fdata[23] = substr($data[0],466,20);	if(!frm_fldcheck($fdata[23],'NUM',20,1)){$MSG_ERR = 23;} 															$ftdata_extend .=	'"'.trim($fdata[23]).'",';							#RECIPIENT PHONE	R	20	Numeric
		$fdata[24] = substr($data[0],486,2);	if(!frm_fldcheck($fdata[24],'ALP',2,1)){$MSG_ERR = 24;}$fdata[24]=isocode_replace($__sysCountries,'p'.$fdata[24],1);$ftdata_extend .=	'"'.trim($fdata[24]).'",';							#RECIPIENT COUNTRY	R	2	Alphanumeric
		$fdata[25] = substr($data[0],488,1);	if(!frm_fldcheck($fdata[25],'ALP',1,1)){$MSG_ERR = 25;}$fdata[25]=isocode_replace($__sysPaymentMode,'p'.$fdata[25],0);$ftdata .=	$fdata[25].',';											#PAYMENT METHOD	R	1	Alphanumeric
		$fdata[26] = substr($data[0],489,8);	if(!frm_fldcheck($fdata[26],'ALP',8,8)){$MSG_ERR = 26;}															 #	$ftdata_extend .=	'"'.$fdata[26].'",';								#BANK NACIONAL CODE	(D)	8	Alphanumeric
		$fdata[27] = substr($data[0],497,25);	if(!frm_fldcheck($fdata[27],'ALP',25,1)){$MSG_ERR = 27;}$fdata[27]=isocode_replace($__sysBanks,'p'.$fdata[24].'^*^'.trim($fdata[27]).'^*^'.$fdata[26],1);$ftdata_extend .=	$fdata[27].',';	#BANK NAME	(D)	25	Alphanumeric
		$fdata[28] = substr($data[0],522,25);	if(!frm_fldcheck($fdata[28],'ALP',25,1)){$MSG_ERR = 28;}															$ftdata_extend .=	'"'.$fdata[28].'",';								#BRANCH NUMBER	(D)	25	Alphanumeric
		$fdata[29] = substr($data[0],547,10);	if(!frm_fldcheck($fdata[29],'ALP',10,1)){$MSG_ERR = 29;} $fdata[29]=isocode_replace($__sysRcvAcountType,'p'.$fdata[29],0);$ftdata_extend .=	$fdata[29].',';									#ACCOUNT TYPE	(D)	10	Alphanumeric
		$fdata[30] = substr($data[0],557,25);	if(!frm_fldcheck($fdata[30],'ALP',25,1)){$MSG_ERR = 30;} 															$ftdata_extend .=	'"'.$fdata[30].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
		$fdata[31] = substr($data[0],582,8);	if(!frm_fldcheck($fdata[31],'ALP',8,1)){$MSG_ERR = 31;} $fdata[31]=isocode_replace($__sysAgencies,'p'.$fdata[31],0);$ftdata .=	$fdata[31].',';												#PAYING OFFICE/AGENT	(P)	8	Alphanumeric
		# Se balcao invalido adiciona �s observacoes
		if($fdata[31]==0 && $fdata[25]==0){ 													$ftdata .= '": Codigo de Agencia Invalido: '.$fdata[31].'",'; } else {$ftdata .= 'null,';}													# SYS OBS
		$fdata[32] = substr($data[0],590,16);	if(!frm_fldcheck($fdata[32],'ALP',16,1)){$MSG_ERR = 32;}
		$ftdata .=	'"'.trim($fdata[32]).'",';									#MTCN REFERENCE	(P)	16	Alphanumeric
		$fdata[33] = 0;	if(!frm_fldcheck($fdata[33],'INT',5,1)){$MSG_ERR = 33;} 															$ftdata_extend .=		$fdata[33].',';							#RECIPIENT COUNTRY	R	20	Alphanumeric
		$fdata[34] = 0;		if(!frm_fldcheck($fdata[34],'ALP',100,1)){$MSG_ERR = 34;} 															$ftdata_extend .=	'"'.$fdata[34].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
		$fdata[35] = 0;		if(!frm_fldcheck($fdata[35],'ALP',20,1)){$MSG_ERR = 35;} 															$ftdata_extend .=	'"'.$fdata[35].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
		$fdata[36] = 0;		if(!frm_fldcheck($fdata[36],'ALP',20,1)){$MSG_ERR = 36;} 															$ftdata_extend .=	'"'.$fdata[36].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
		$fdata[37] = 0;		if(!frm_fldcheck($fdata[37],'ALP',20,1)){$MSG_ERR = 37;} 															$ftdata_extend .=	'"'.$fdata[37].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
		$fdata[38] = 0;		if(!frm_fldcheck($fdata[38],'ALP',45,1)){$MSG_ERR = 38;} 															$ftdata_extend .=	isocode_replace($__sysCities,'p'.$fdata[38],1);									#ACCOUNT NUMBER	(D)	25	Alphanumeric
		$fdata[39] = 1;		if(!frm_fldcheck($fdata[39],'INT',10,1)){$MSG_ERR = 39;} 															$ftdata_income .=	$fdata[39];									#ACCOUNT NUMBER	(D)	25	Alphanumeric

		$ftdata .= '2,2),';
		$ftdata_extend .= '),';
		$ftdata_income .= '),';

		$SUMTransactionA += $fdata[5];
		$SUMTransactionB += $fdata[8];

	}
}